package handlers

import (
	"github.com/gin-gonic/gin"
	"user-access/models"
	"user-access/pkg"
)

func UserLogin(c *gin.Context) {
	username := c.PostForm("username")
	tell := c.PostForm("tell")
	if username == "" || tell == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}
	var user models.User
	if user.Tell != pkg.Md5(tell) {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "密码错误",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "登录成功",
	})
	return

}
func ArticleList(c *gin.Context) {
	title := c.PostForm("title")
	comment := c.PostForm("comment")
	data := models.Article{
		Title:   title,
		Comment: comment,
	}
	models.DB.Find(&data)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": data,
	})
	return
}
